package com.eh;

import com.eh.encription.SecurityUtils;
import com.google.common.collect.Maps;
import com.sun.org.apache.xml.internal.security.utils.Base64;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.MathContext;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by David Li on 2016/3/14.
 */
public class SomeTest {
    private static Logger logger = LoggerFactory.getLogger(SomeTest.class);
    private static final String CHARSET = "utf-8";
    private static final String Algorithm = "DESede";

    public static void main(String[] args) throws ParseException, UnsupportedEncodingException {
        B b = new B();
        b.setS1("s1");
        b.setI(1);
        A a = new A();
        a.setS1("s2");
        a.setI(2);
        a.setB(b);
        a(a);
        System.out.println(a);
    }

    private static void a(A a) {
        a.setS1("SSS");
        a.setI(123);
        B b = a.getB();
        b.setI(123);
        b.setS1("SSS");
    }


    private static Date calculateRepayDay(Date date, int num) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        /** 28号 */
        Calendar c1 = Calendar.getInstance();
        c1.set(Calendar.DAY_OF_MONTH, 28);
        c1.set(Calendar.HOUR_OF_DAY, 23);
        c1.set(Calendar.MINUTE, 59);
        c1.set(Calendar.SECOND, 59);
        if (c.getTimeInMillis() < c1.getTimeInMillis()) {
            c.add(Calendar.MONTH, num);
            c.set(Calendar.HOUR_OF_DAY, 23);
            c.set(Calendar.MINUTE, 59);
            c.set(Calendar.SECOND, 59);
            return c.getTime();
        }
        c.add(Calendar.MONTH, num);
        c.set(Calendar.DAY_OF_MONTH, 28);
        c.set(Calendar.HOUR_OF_DAY, 23);
        c.set(Calendar.MINUTE, 59);
        c.set(Calendar.SECOND, 59);
        return c.getTime();
    }

    private static void test1() throws ParseException {
        Date date = new SimpleDateFormat("yyyyMMddHHmmSS").parse("20160708071359");
        System.out.println(new SimpleDateFormat("yyyyMMddHHmmSS").format(date));
        Calendar cd = Calendar.getInstance();
        cd.setTime(date);
        System.out.println(new SimpleDateFormat("yyyyMMddHHmmSS").format(cd.getTime()));
    }

    private static void test2() {
        Calendar c = Calendar.getInstance();
        System.out.println(c.get(Calendar.MONTH) + 1);
    }

    private static void test3() {
        Calendar c = Calendar.getInstance();
        System.out.println(c.get(Calendar.DAY_OF_MONTH));
    }

    private static void test4() {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.DAY_OF_MONTH, 1);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        System.out.println(new SimpleDateFormat("yyyyMMddHHmmSS").format(c.getTime()));
    }

    private static void test5() {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.DAY_OF_MONTH, 1);
        c.add(Calendar.DAY_OF_MONTH, 20);
        System.out.println(new SimpleDateFormat("yyyyMMddHHmmSS").format(c.getTime()));
    }

    private static void test6() {
        Date date = new Date();
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmmSSs");
        System.out.println(sdf1.format(date));
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmSS");
        System.out.println(sdf2.format(date));
        SimpleDateFormat sdf3 = new SimpleDateFormat("yyyyMMddHHmmssS");
        System.out.println(sdf3.format(date));
        SimpleDateFormat sdf4 = new SimpleDateFormat("yyyyMMddHHmmss");
        System.out.println(sdf4.format(date));
    }

    private static void test7() throws ParseException {
        Date date = new SimpleDateFormat("yyyyMMdd").parse("2016-01-01");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, -1);
        System.out.println(new SimpleDateFormat("yyyyMM").format(calendar.getTime()));
    }


}

@Data
class A{
    private String s1;
    private int i;
    private B b;
}


@Data
class B{
    private String s1;
    private int i;
}

